package com.neusoft.actor.controller;

import com.neusoft.actor.po.CaretakerClient;
import com.neusoft.actor.po.Client;
import com.neusoft.actor.po.ResponseBean;
import com.neusoft.actor.service.CaretakerClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin("*")
@RequestMapping("/CaretakerClientController")
public class CaretakerClientController {

    @Autowired
    private CaretakerClientService caretakerClientService;

    @GetMapping
    public ResponseBean<List<CaretakerClient>> getAllCaretakerClients() {
        return caretakerClientService.getAllCaretakerClients();
    }

    @GetMapping("/{id}")
    public ResponseBean<CaretakerClient> getCaretakerClientById(@PathVariable Integer id) {
        return caretakerClientService.getCaretakerClientById(id);
    }

    @GetMapping("/getCaretakerClientByCaretakerId")
//    根据健康管家id查询健康管家服务的的客户,可以根据姓名模糊查询
    public ResponseBean<List<Client>> getCaretakerClientByCaretakerId(@RequestParam Integer id, @RequestParam(required = false) String clientName) {
        return caretakerClientService.getCaretakerClientByCaretakerId(id, clientName);
    }

    @PostMapping("/addCaretakerClient")
//    给客户新增健康管家,给客户id和健康管家id
    public ResponseBean<Integer> addCaretakerClient(@RequestParam Integer clientId, @RequestParam Integer caretakerId) {
        return caretakerClientService.addCaretakerClient(clientId, caretakerId);
    }

    @PutMapping("/{id}")
    public ResponseBean<Integer> updateCaretakerClient(@PathVariable Integer id, @RequestBody CaretakerClient caretakerClient) {
        caretakerClient.setRelationId(id);
        return caretakerClientService.updateCaretakerClient(caretakerClient);
    }

    @DeleteMapping("/deleteCaretakerClient")
//    移除某客户的管家，给客户id即可
    public ResponseBean<Integer> deleteCaretakerClient(@RequestParam Integer clientId) {
        return caretakerClientService.deleteCaretakerClient(clientId);
    }
}